package com.example.book.controller;


import com.example.book.entity.Chapter;
import com.example.book.service.IChapterService;
import com.example.common.dtos.ResponseResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-12-01
 */
@RestController
@RequestMapping("/chapter")
public class ChapterController {
    @Autowired
    private IChapterService chapterService;

    /**
     * 发布新章节
     * @param chapter
     * @return
     */
    @PostMapping
    public ResponseResult addChapter(@RequestBody Chapter chapter){
        return ResponseResult.okResult(chapterService.addChapter(chapter));
    }

    /**
     * 查看图书全部章节
     * @param bookId
     * @return
     */
    @GetMapping("/{bookId}")
    public ResponseResult queryChapterAll(@PathVariable Long bookId){

        return ResponseResult.okResult(chapterService.queryChapterAll(bookId));
    }

    /**
     * 根据章节id数据回显
     * @param chapterId
     * @return
     */
    @GetMapping("/edit/{chapterId}")
    public ResponseResult queryChapterById(@PathVariable Long chapterId){

        return ResponseResult.okResult(chapterService.queryChapterById(chapterId));
    }

    /**
     * 删除
     * @param chapterId
     * @return
     */
    @DeleteMapping
    public ResponseResult delete(Long chapterId) {
        return ResponseResult.okResult(chapterService.delete(chapterId));
    }
}

